package io.renren.controller;


import io.renren.common.utils.R;
import io.renren.util.ApiBaseAction;
import io.renren.util.QiniuUploadHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/***
 * 上传文件
 */
@RestController
@RequestMapping("/api/upload")
public class ApiUploadController extends ApiBaseAction {

    /**
     * 上传文件
     */
    @RequestMapping("/upload")
    public Object upload(@RequestParam("file") MultipartFile file) throws Exception {
        String key = System.currentTimeMillis() + "";

        boolean flag = QiniuUploadHelper.uploadMultipartFile(file, key, true);

        if (!flag) {
            return R.error("上传失败");
        }

        String url = QiniuUploadHelper.fileUrl(key);

        return R.ok(url);
    }


}